import org.junit.Test;


import java.io.IOException;
import java.nio.file.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 文件筛选
 */
public  class FileScreen {

    public static void main(String[] args) throws IOException {

        // 源目录和目标目录的路径
        Path sourceDirectory = Paths.get("C:\\Users\\DELL\\Desktop\\data\\data");
        Path destinationDirectory = Paths.get("C:\\Users\\DELL\\Desktop\\desData");

        List<String> fileNames  = Arrays.asList("rBEABGN0UKSADIBXAAfXaDegfYM138.pdf",
                "rBEABGTIW0mAC6tVAAvYTHKqudU891.zip",
                "rBEABGTJqgmAMmmTAAvYTHKqudU248.zip",
                "rBEABGTMSGGAQPCIAAt7isjc-8Y495.zip",
                "rBEABGTMsdeAODgSAAZ0KvTjp00153.zip",
                "rBEABGTPt9uATRtgABUztuoP87k871.zip",
                "rBEABGTR_VKAbOl8ABZAyR7k_lo661.zip",
                "rBEABGTUhbGAA6dtAAcFwdf225E340.zip",
                "rBEABGTZlbqAQkE9AAs7srCUr50805.zip",
                "rBEABGTZzUiAO08nADNXNV65IbM220.zip",
                "rBEABGTZ0PCAGNz0AGY34eY0mig760.zip",
                "rBEABGTZ0RiAQauAABk6Q61q6rg734.zip",
                "rBEABGTZ2bWACI7EABE6PbiLn_k684.zip",
                "rBEABGTZ7TGAIdgVAAbJ460MVQQ538.zip",
                "rBEABGTZ9FCAFl1JABaqYeh_f8U970.zip",
                "rBEABGTa3RqAJyw3ABufbQsvI0A371.zip",
                "rBEABGTa4bqAEjVuAAAxOj04hUg834.zip",
                "rBEABGTa4kuAdG1XABR0omBwAdA982.zip",
                "rBEABGTa4l6AP5eBACxcVNQmmzo960.zip",
                "rBEABGTa4niASC04AI92gYk5hKk023.zip",
                "rBEABGTa4oSAQVsbAAA0Rf2QBRw380.zip",
                "rBEABGTa46aABnSOAAA4FEvfaIU094.zip",
                "rBEABGTa5GGAAoC2AAA1uNAbk1U252.zip",
                "rBEABGTa5oaAKYMtACRilUmPNyg418.zip",
                "rBEABGTa5paANXuaABci_R7PEyI787.zip",
                "rBEABGTa5rCAMrobAB6VlgLj1UY344.zip",
                "rBEABGTa5r-ALT0JAA7FkNbkVNo509.zip",
                "rBEABGTbI3eAOWWLADG5-cFZPVc574.zip",
                "rBEABGTbJGqAJzHHAAiT2j-hVkw277.zip",
                "rBEABGTbNymAaE5mAAw0tXF6WSc993.zip",
                "rBEABGTbN0uASklNAAdq6v52sFs743.zip",
                "rBEABGTbOP-AeVYdAD06EF-HEKw681.zip",
                "rBEABGTbOryAWWl6AOGTAvZ2ycg713.zip",
                "rBEABGTbPnGAep-UAD06EF-HEKw376.zip",
                "rBEABGTbVCeAXfAZAAJlXaevAh4505.zip",
                "rBEABGTbVQ2AZfYSAAB-GRlm2rg252.zip",
                "rBEABGTbYYOANLaHAAgA1EFRtXo086.zip",
                "rBEABGTcgoOAUT5lAB2luVsJDhU051.zip",
                "rBEABGTcteqALRy3AB-6up9EDH0967.zip",
                "rBEABGTdaPOADvAtACU8KUsO7bE097.zip",
                "rBEABGTdauiAKO8YAAeQ_dklGY8656.zip",
                "rBEABGTda6mAESviABe8ZiPcj1w683.zip",
                "rBEABGTdbFiADch9ADFZiIiERdE278.zip",
                "rBEABGTdbFiADch9ADFZiIiERdE278.zip",
                "rBEABGTdbUyAGk7iAASMklzdacg256.zip",
                "rBEABGTdbVaAK68UAAFSuwBMi1A551.zip",
                "rBEABGTdd1GAI-92AASMklzdacg545.zip",
                "rBEABGTdd5GAEDCyAASMklzdacg920.zip",
                "rBEABGTdeBKANf4_AASMklzdacg348.zip",
                "rBEABGTdev2ACInEAASMklzdacg181.zip",
                "rBEABGTdezSADY78AASMklzdacg988.zip",
                "rBEABGTde32AM7oLAASMklzdacg210.zip",
                "rBEABGTde66AeMxGAB-6up9EDH0091.zip",
                "rBEABWTdskuAYNWQAAp9aRw45DM517.zip",
                "rBEABWTdsoiAfvyBADVsP8wxsRA825.zip",
                "rBEABWTdspmAMD8VAAp5DdqxMPg732.zip",
                "rBEABWTdsqaAH87iAAqb-HNNnmw888.zip",
                "rBEABWTdsrqAcom9AEuuHycI3EY157.zip",
                "rBEABWTdssyAQYvvAAE1CQclyH8647.zip",
                "rBEABWTdsyiAOODoAAP09gy1kr8155.zip",
                "rBEABWTds2OAewXRAQX4zRaxwlQ925.zip",
                "rBEABWTds36Af2blAATsktFeeoc961.zip",
                "rBEABWTds42AXKPHAA3BI7HPK50427.zip",
                "rBEABWTds7mAADZZAHF5uWkCvAc659.zip",
                "rBEABWTds8yASibTAA7KAUJqij8612.zip",
                "rBEABWTds--Abo6mAAbj__EAt9o289.zip",
                "rBEABWTdtD-ALINpAAUe_ceXNX8194.zip",
                "rBEABWTdtEyAQ01zAAqBYIKYnEA528.zip",
                "rBEABWTdtFuAG1GLAAe0yotpn40803.zip",
                "rBEABWTdtGyAPpkJAAZ5NU977Kc404.zip",
                "rBEABWTdtHmACIsOAAYs3Xy4lhQ341.zip",
                "rBEABWTdtIqACeEgAAW38uS37kE140.zip",
                "rBEABWTdtLOAJgMXAAOrrizVPDM231.zip",
                "rBEABWTdtMaASR34AAJ1IyFFTOo736.zip",
                "rBEABWTdtN-AAFj8AAmnEThvs9A460.zip",
                "rBEABWTdtPGAbxuYAAS7Wkuku-M267.zip",
                "rBEABWTdtQOAeJ4_AASxZ3kVFy4525.zip",
                "rBEABWTdtRWAM-f2AAHvlnJPifY507.zip",
                "rBEABWTdtR-AcvTOAAG4sImNUKM287.zip",
                "rBEABWTdtb-AVcRvABi_n9VV8c4834.zip",
                "rBEABWTdtfGAd0j-AAXCgXM7XyE244.zip",
                "rBEABWTdtgCAXJ1UABpkZAJSktk037.zip",
                "rBEABWTdtg6AcfNIAAZnkARblSA846.zip",
                "rBEABWTdthqASGaFAAFm7hf1Q2Q835.zip",
                "rBEABWTdtjiAa1DJAEUuF3UivVI417.zip",
                "rBEABWTdtlKAB-fiAAdY_UHGr5A733.zip",
                "rBEABWTdtmuAft9KACSMhLZxoRM634.zip",
                "rBEABWTdtoCAPGLBAAPPKLNKYzk978.zip",
                "rBEABWTdto2AKtDNAARQzOgMzRk313.zip",
                "rBEABWTdtpyADm9fAAjKztLPJC8326.zip",
                "rBEABWTdtqWANHE4AAZhqCxCbnA091.zip",
                "rBEABWTdtrqAMzO0AAYpKNb36vA577.zip",
                "rBEABWTdtsmAPApoAAQtR11TI6w402.zip",
                "rBEABWTdttuAVEVdAAEFwoMXrpM107.zip",
                "rBEABWTdtu-AFaewAAqBrQQ3Usk028.zip",
                "rBEABWTdtvqAMtxrAAIVTFwqldQ539.zip",
                "rBEABWTdtxyAEbEKAAXcZfRUdJU028.zip",
                "rBEABWTdt1-AeOruAAT6ZLdWInE370.zip",
                "rBEABWTdyvqACuEkAAWgfO60OU4578.zip",
                "rBEABWTdyxyAOoeBAAX4f3UlaPE405.zip",
                "rBEABWTdyzGALlTlAASfAhKwBuM485.zip",
                "rBEABWTdy3qAeTXzAAPHlJtOknY306.zip",
                "rBEABWTdy46AKTzeAAiXBJ3kTig286.zip",
                "rBEABWTdy6KAATHuABrRCpB9-tI641.zip",
                "rBEABWTdy7OALavzAAqIeVmQD1A737.zip",
                "rBEABWTdzJ-AemRVABIZTRyDc0o889.zip",
                "rBEABWTdy-SAbMq6AEPMVBgLgSc099.zip",
                "rBEABWTdy_aAFrQ2AB7cIYC1IYQ254.zip",
                "rBEABWTdzAyAV7LTADbITLw0M78228.zip",
                "rBEABWTdzBuAMAPaAAA8cA5q0Eg060.zip",
                "rBEABWTdzC-Ac2owAAWqkYXy-Ug259.zip",
                "rBEABWTdzDmATmI-AANasZqKRlA474.zip",
                "rBEABWTdzE2AK8L1AAiE4hqKxwA073.zip",
                "rBEABWTdzFaAKmwHAAHk2SJ5xAM992.zip",
                "rBEABWTdzGGAGIDcAAOCXH31bxE437.zip",
                "rBEABWTdzG-ActilAAO3BSb1IrY232.zip",
                "rBEABWTdzH6AQ18OAAFwk02f2MI637.zip",
                "rBEABWTdzJ-AemRVABIZTRyDc0o889.zip",
                "rBEABWTd0HeACv29AAGCFT21-Jo613.zip",
                "rBEABWTd3HSACDP_ACkZIt_JEq4015.zip",
                "rBEABWTd3NuATbG2ACkZIt_JEq4092.zip",
                "rBEABWTd3USActD2ACkZIt_JEq4892.zip",
                "rBEABGTZ_L-ANWs0AEFuidVS8gI666.zip",
                "rBEABGTZeEqAVuvLACv-hG3E1lM301.zip",
                "rBEABGTcb5eAdhXkAA6bIwOnEWo896.zip",
                "rBEABGTZo5iAFAkMADCSrDZdVL8885.zip",
                "rBEABGTTMwSAZ5-lACTukosiKJ4405.zip",
                "rBEABGTV7u2ADNpHAAhcKXMYm2M409.zip",
                "rBEABGTV7wuAUsfKAAxcQbLwfE0265.zip",
                "rBEABGTZeGSABBAGAAYJ41JHCxA404.zip",
                "rBEABGTZjbOAWNlZAP5uhUNKKZk827.zip",
                "rBEABGTZ3dGAfZUdACeN-E5Je0o941.zip",
                "rBEABGTZkYmAaP6xAAk_UUAm3lk562.zip",
                "rBEABGTZeQOAK5EIAAo8uY3XULQ165.zip",
                "rBEABGTZeIyAcnMpAALu2Zk2Qjk065.zip",
                "rBEABGTZeTWAYvNvAAOGJugRa38584.zip",
                "rBEABGTZkeuARQxvADIHWvdhGrU540.zip",
                "rBEABGTZ8ayAQ7YdAAVp4TlzceY498.zip",
                "rBEABGTZ8dGAW2wRAAs7srCUr50019.zip",
                "rBEABGTZoriAYIGuAAeMvPXlsnw094.zip",
                "rBEABGTZpceAOsR9AAqbFB4f4iQ220.zip ",
                "rBEABGTZo8KAJ8SCAAXgZK9xCh4477.zip",
                "rBEABGTZnFKAIbuyABJ-BVGLtaU499.zip",
                "rBEABGTbOKOANzsmAEw_TGGpkew654.zip ",
                "rBEABGTaHMOAM9A1ACMx4zT6RAQ546.zip",
                "rBEABGTaHIOAC0EcAAYN-CjMUTY025.zip",
                "rBEABGTaG_iANEy8ACPE4aZglOE567.zip",
                "rBEABGTaHCKAWKoKAAdeqYd6IA0456.zip",
                "rBEABGTaG66AEUNQAAh-FqLaArY840.zip",
                "rBEABGTbNuGAPezwAApJeTqegC0740.zip",
                "rBEABGTbNxCAJhmRABZDD0u1ig0056.zip",
                "rBEABGTbNLOAAdcbAASn-RQY8Hs742.zip",
                "rBEABGTbN2uAWv3uAA6Zne00-7k697.zip",
                "rBEABGTbN_aALa7yAB34svMMWQA130.zip",
                "rBEABGTbcS-AFWW2ABziYGUlIaQ698.zip",
                "rBEABGTcVgmAazPEABwYC6VntLg594.zip");


        // 用于跟踪已拷贝的文件名集合
        Set<String> copiedFileNames = new HashSet<>();

        try {
            // 遍历源目录及其子目录下的所有文件
            Files.walk(sourceDirectory)
                    .filter(sourcePath -> Files.isRegularFile(sourcePath))  // 过滤出普通文件
                    .forEach(sourcePath -> {
                        String fileName = sourcePath.getFileName().toString();

                        // 如果文件名不在已拷贝和排除的列表中
                        if (!copiedFileNames.contains(fileName) && !fileNames.contains(fileName)) {
                            // 构建目标文件路径
                            Path destinationFile = destinationDirectory.resolve(fileName);

                            try {
                                // 复制文件到目标目录
                                Files.copy(sourcePath, destinationFile);
                                copiedFileNames.add(fileName);  // 将文件名添加到已拷贝集合
                                System.out.println("拷贝文件路径: " + sourcePath);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @Test
    public void test22() throws IOException {

        Path sourceDirectory = Paths.get("F:\\BaiduNetdiskDownload\\shengou-2023\\abc");
        Path destinationDirectory = Paths.get("F:\\BaiduNetdiskDownload\\shengou-2023\\abc22");

        String excludedFileName = "exclude.txt";

        Files.walk(sourceDirectory)
                .filter(sourcePath -> !sourcePath.getFileName().toString().equals(excludedFileName))
                .forEach(sourcePath -> {
                    if (Files.isRegularFile(sourcePath)) {
                        Path destinationFile = destinationDirectory.resolve(sourcePath.getFileName());
                        if (!Files.exists(destinationFile)) {
                            try {
                                Files.copy(sourcePath, destinationFile);
                                System.out.println("拷贝文件路径: " + sourcePath);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
    }


}